package com.example.planstudio;

import android.app.Activity;
import android.app.SharedElementCallback;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
//import com.example.myapplication.R;

public class choose_player extends AppCompatActivity implements View.OnClickListener{

    private String et_name;
    private String et_ip;
    private String et_port;
    Context ctx;
    int resId;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        System.out.println("启动2");
        //启动活动，并获取传递过来的信息

        //传入键值得到数据
//        et_name = intent.getStringExtra("name");
//        et_ip = intent.getStringExtra("ip");
//        et_port = intent.getStringExtra("port");
        Button button1 = (Button)findViewById(R.id.one);
        Button button2 = (Button)findViewById(R.id.two);
        Button button3 = (Button)findViewById(R.id.three);
        Button button4 = (Button)findViewById(R.id.four);
        Button button5 = (Button)findViewById(R.id.five);
        Button button6 = (Button)findViewById(R.id.six);
        Button button7 = (Button)findViewById(R.id.seven);
        Button button8 = (Button)findViewById(R.id.eight);
        Button button9 = (Button)findViewById(R.id.nine);
        Button button_cancel = (Button)findViewById(R.id.cancel);
        Button button_ensure = (Button)findViewById(R.id.ensure);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
        button6.setOnClickListener(this);
        button7.setOnClickListener(this);
        button8.setOnClickListener(this);
        button9.setOnClickListener(this);
        button_cancel.setOnClickListener(this);
        button_ensure.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        //向下一活动传递信息
//        Intent intent = new Intent(ChoosePicture.this,ChatRoom.class);
//        intent.putExtra("name",et_name.toString());
//        intent.putExtra("ip",et_ip.toString());
//        intent.putExtra("port",et_port.toString());
        switch(view.getId()){
            case R.id.one:
                ctx = getBaseContext();
                resId = getResources().getIdentifier("client", "drawable", ctx.getPackageName());
                System.out.println(resId);
//                intent.putExtra("imageId",R.drawable.headofothers);
                break;
            case R.id.two:
//                intent.putExtra("imageId",R.drawable.headofmy);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.three:
//                intent.putExtra("imageId",R.drawable.three);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server2", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.four:
//                intent.putExtra("imageId",R.drawable.six);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server3", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.five:
//                intent.putExtra("imageId",R.drawable.four);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server4", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.six:
//                intent.putExtra("imageId",R.drawable.five);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server5", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.seven:
//                intent.putExtra("imageId",R.drawable.five);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server6", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.eight:
//                intent.putExtra("imageId",R.drawable.five);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server7", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.nine:
//                intent.putExtra("imageId",R.drawable.five);
                ctx = getBaseContext();
                resId = getResources().getIdentifier("server8", "drawable", ctx.getPackageName());
                System.out.println(resId);
                break;
            case R.id.cancel:
                finish();
                break;
            case R.id.ensure:
//                Intent intent1 = new
//                        Intent(choose_player.this,MoneyActivity.class);
//                intent1.putExtra("role",2131165294);
//                startActivity(intent1);
                SharedPreferences preferences=getSharedPreferences("value",0);
                SharedPreferences.Editor editor = preferences.edit();
//                MydataHelper DB=new MydataHelper(this) ;
//                role role1;
//                role1=DB.getrole(resId);
////                System.out.print(role1.getName());
//                adapter.setServer_name(role1.getName());
                editor.putInt("value",resId);
                if(editor.commit()){
                    setResult(Activity.RESULT_OK);
                }
                finish();
        }
//        startActivity(intent);
    }

}
